<?php
import("Weixin.Util.jssdk");
$jssdk = new JSSDK("wx1509e46e90775fe4", "203f4fefd0fc676e1e7c28f28a9ccec5");
$signPackage = $jssdk->GetSignPackage();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="__CSS__/materialize.min.css" rel="stylesheet">
    <script src="__JS__/jquery.min.js"></script>
    <script src="__JS__/materialize.min.js"></script>
    <link href="__CSS__/engineer-index.css" rel="stylesheet">
    <title>功能选择</title>
</head>
<body>
    <div class="section bgc-blue">
        <a href="#0" class="center-a">
            <img class="responsive-img" src="__IMG__/logo.png">
        </a>
    </div>
    <div class="line"></div>
    <div class="container">
        <div class="row">
            <div class="col s12 m6 offset-m3 l6 offset-l3">
                <div class="col s4 m4">
                    <a id="scanQRCode7777">
                        <div class="card-panel module01 center">
                            <img class="responsive-img" src="__IMG__/report.png">
                            <br>
                            <span class="white-text">报&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;修</span>
                        </div>
                    </a>
                </div>
                <div class="col s4 m4">
                    <a id="scanQRCode">
                        <div class="card-panel module02 center">
                            <img class="responsive-img" src="__IMG__/repair.png">
                            <br>
                            <span class="white-text">维&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;修</span>
                        </div>
                    </a>
                </div>
                <div class="col s4 m4">
                    <a id="scanQRCode2">
                        <div class="card-panel module03 center">
                            <img class="responsive-img" src="__IMG__/patrol.png">
                            <br>
                            <span class="white-text">巡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;检</span>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col s12 m6 offset-m3 l6 offset-l3">
                <div class="col s4 m4">
                    <a id="scanQRCode1">
                        <div class="card-panel module04 center">
                            <img class="responsive-img" src="__IMG__/pm.png">
                            <br>
                            <span class="white-text">PM检测</span>
                        </div>
                    </a>
                </div>
                <div class="col s4 m4">
                    <a id="scanQRCode3">
                        <div class="card-panel module05 center">
                            <img class="responsive-img" src="__IMG__/performance.png">
                            <br>
                            <span class="white-text">性能检测</span>
                        </div>
                    </a>
                </div>
                <div class="col s4 m4">
                    <a id="scanQRCode7777">
                        <div class="card-panel module06 center">
                            <img class="responsive-img" src="__IMG__/mine.png">
                            <br>
                            <span class="white-text">我&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;的</span>
                        </div>
                    </a>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"> </script>
<script>
    wx.config({
      debug: false,
      appId: '<?php echo $signPackage["appId"];?>', 
      timestamp: <?php echo $signPackage["timestamp"];?>,
      nonceStr: '<?php echo $signPackage["nonceStr"];?>', 
      signature: '<?php echo $signPackage["signature"];?>',
      jsApiList: [
        'checkJsApi',
        'scanQRCode',
        'scanQRCode1',
        'scanQRCode2',
        'scanQRCode3',
      ]
    });

    wx.ready(function(){
        //1.检查扫一扫接口
        document.querySelector('#scanQRCode').onclick = function () {
        wx.scanQRCode({
          needResult: 1,
          desc: 'scanQRCode desc',
          success: function (res) {  
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            var act = "act";
            var host = window.location.host; 
            var url = "http://"+host+"/index.php/weixin/manage/getqrcodes/action/"+act;
            getqrcodes(result,act,url);
          }
        });
        };
    });

    wx.ready(function(){
        //1.检查扫一扫接口
        document.querySelector('#scanQRCode1').onclick = function () {
        wx.scanQRCode({
          needResult: 1,
          desc: 'scanQRCode desc',
          success: function (res) {  
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            var act = "act1";
            var host = window.location.host; 
            var url = "http://"+host+"/index.php/weixin/manage/getqrcodes/action/"+act;
            getqrcodes(result,act,url);
          }
        });
        };
    });

    wx.ready(function(){
        //1.检查扫一扫接口
        document.querySelector('#scanQRCode2').onclick = function () {
        wx.scanQRCode({
          needResult: 1,
          desc: 'scanQRCode desc',
          success: function (res) {  
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            var act = "act2";
            var host = window.location.host; 
            var url = "http://"+host+"/index.php/weixin/manage/getqrcodes/action/"+act;
            getqrcodes(result,act,url);
          }
        });
        };
    });

    wx.ready(function(){
        //1.检查扫一扫接口
        document.querySelector('#scanQRCode3').onclick = function () {
        wx.scanQRCode({
          needResult: 1,
          desc: 'scanQRCode desc',
          success: function (res) {  
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            var act = "act3";
            var host = window.location.host; 
            var url = "http://"+host+"/index.php/weixin/manage/getqrcodes/action/"+act;
            getqrcodes(result,act,url);
          }
        });
        };
    });

    wx.error(function (res) {
      alert(res.errMsg);
    });

    function getqrcodes(result,act,url){    
        var my_data=result;
        var action = act;
        $.ajax({
           type: "POST",
           url: url,
           data: {codes:my_data},
           success: function(response,status,xsr){
                if(response){
                  var jsonobj=eval('('+response+')');
                  var success = jsonobj.success;
                  if(success){
                    var url = jsonobj.url;
                    var did = jsonobj.did;
                    window.location.href = url+"/did/"+did; 
                  }else{
                    alert("该功能暂未开通");
                  }
                }
            },
            error: function(){  
                 alert('设备扫描出错啦，请尽快联系管理员~');  
            }
        });
    }


</script>
</html>